<style>
    #febs-transferApplication xm-select {
        min-height: 30px;
        line-height: 30px;
    }

    #febs-transferApplication xm-select > .xm-label .scroll .label-content {
        display: flex;
        padding: 0 30px 0 10px;
    }
</style>
<div class="layui-fluid layui-anim febs-anim" id="businesses-transferApplication" lay-title="异动申请信息">
    <div class="layui-row febs-container">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body febs-table-full">
                    <form class="layui-form layui-table-form" lay-filter="transferApplication-table-form">
                        <fieldset class="layui-elem-field layui-field-title" style="margin-top: 10px;">
                            <legend style="font-size: 15px; font-weight: bolder;">批量查询</legend>
                        </fieldset>
                        <div class="layui-row">
                            <div class="layui-col-md10">
                                <div class="layui-form-item">
                                    <div class="layui-inline">
                                        <label class="layui-form-label layui-form-label-sm">批次</label>
                                        <div class="layui-input-inline">
                                            <select name="batchId" id="businesses-transferApplication-cboBatch"
                                                    lay-filter="cboBatch">
                                                <option value=""></option>
                                            </select>
                                        </div>
                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label layui-form-label-sm">院校</label>
                                        <div class="layui-input-inline">
                                            <select name="collegeId" id="businesses-transferApplication-cboCollege"
                                                    lay-filter="cboCollege">
                                                <option value=""></option>
                                            </select>
                                        </div>
                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label layui-form-label-sm">层次</label>
                                        <div class="layui-input-inline">
                                            <select name="level" id="businesses-transferApplication-cboLevel"
                                                    lay-filter="cboLevel">
                                                <option value=""></option>
                                            </select>
                                        </div>
                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label layui-form-label-sm">专业</label>
                                        <div class="layui-input-inline">
                                            <select name="majorId" id="businesses-transferApplication-cboMajor"
                                                    lay-filter="cboMajor">
                                                <option value=""></option>
                                            </select>
                                        </div>
                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label layui-form-label-sm">班主任</label>
                                        <div class="layui-input-inline">
                                            <input type="text" name="userId" id="transferApplication-cboUser"
                                                   lay-filter="transferApplication-cboUser" class="layui-input">
                                        </div>
                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label layui-form-label-sm">异动类型</label>
                                        <div class="layui-input-inline">
                                            <select name="transferTypeId"
                                                    id="businesses-transferApplication-cboTransferType">
                                                <option value=""></option>
                                            </select>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <fieldset class="layui-elem-field layui-field-title" style="margin-top: 10px;">
                            <legend style="font-size: 15px; font-weight: bolder;">精确查询</legend>
                        </fieldset>
                        <div class="layui-row">
                            <div class="layui-col-md10">
                                <div class="layui-form-item">
                                    <div class="layui-inline">
                                        <label class="layui-form-label layui-form-label-sm">姓名</label>
                                        <div class="layui-input-inline">
                                            <input type="text" name="stuName"
                                                   id="businesses-transferApplication-txtStuName" autocomplete="off"
                                                   class="layui-input"
                                                   lay-verify="txt" maxlength="10">
                                        </div>
                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label layui-form-label-sm">身份证号</label>
                                        <div class="layui-input-inline">
                                            <input type="text" name="identity"
                                                   id="businesses-transferApplication-txtIdentity" autocomplete="off"
                                                   class="layui-input"
                                                   lay-verify="dimIdentity" maxlength="18">
                                        </div>
                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label layui-form-label-sm">手机号</label>
                                        <div class="layui-input-inline">
                                            <input type="text" name="tel" id="businesses-transferApplication-txtTel"
                                                   autocomplete="off" class="layui-input"
                                                   lay-verify="number" maxlength="11">
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="layui-col-md2 layui-col-sm12 layui-col-xs12 table-action-area">
                                <div class="layui-btn layui-btn-sm layui-btn-primary febs-button-blue-plain table-action"
                                     lay-submit="" lay-filter="query-form-submit"
                                     id="businesses-transferApplication-query" title="查询">
                                    <i class="layui-icon">&#xe848;</i>
                                </div>
                                <div class="layui-btn layui-btn-sm layui-btn-primary febs-button-green-plain table-action"
                                     id="businesses-transferApplication-reset" title="重置">
                                    <i class="layui-icon" >&#xe79b;</i>
                                </div>
                            </div>
                        </div>
                        <blockquote class="layui-elem-quote layui-quote-nm" style="margin-top: 10px;">
                            <div class="layui-row">
                                <div class="layui-btn layui-btn-sm layui-btn-primary febs-button-blue-plain table-action"
                                     id="businesses-transferApplication-export">
                                    <i class="layui-icon layui-icon-export">导出异动信息</i>
                                </div>
                            </div>
                        </blockquote>
                    </form>
                    <table lay-filter="transferApplicationTable" lay-data="{id: 'transferApplicationTable'}"></table>
                </div>
            </div>
        </div>
    </div>
</div>
<script type="text/html" id="transferApplication-option">
    <a lay-event="edit" title="异动审核"><i
            class="layui-icon febs-edit-area febs-blue">&#xe7a4;</i></a>
</script>
<script type="text/javascript" src="module/treeSelect/treeSelect.js"></script>
<script data-th-inline="none" type="text/javascript">
    layui.use(['treeSelect', 'jquery', 'form', 'table', 'febs', 'validate'], function () {
        let $ = layui.$,
            febs = layui.febs,
            treeSelect = layui.treeSelect,
            form = layui.form,
            table = layui.table,
            $view = $('#businesses-transferApplication'),
            $reset = $view.find('#businesses-transferApplication-reset'),
            $export = $view.find('#businesses-transferApplication-export'),
            $searchForm = $view.find('form'),
            sortObject = {field: 'approvalStatusId', type: null},
            validate = layui.validate,
            tableIns;

        form.verify(validate);
        form.render();

        //查询所有有效批次
        febs.get(ctx + 'college/batchSelect', null, function (data) {
            let list = data.data;
            for (let i = 0; i < list.length; i++) {
                let batch = list[i];
                $("#businesses-transferApplication-cboBatch").append(new Option(batch.batchName, batch.id));
            }
            //重新渲染下拉菜单
            form.render("select");
        });
        //查询所有院校
        febs.get(ctx + 'college/collegeSelect', null, function (data) {
            let list = data.data;
            for (let i = 0; i < list.length; i++) {
                let college = list[i];
                $("#businesses-transferApplication-cboCollege").append(new Option(college.name, college.id));
            }
            //重新渲染下拉菜单
            form.render("select");
        });

        //院校层次联动
        form.on('select(cboCollege)', function (data) {
            let collegeId = data.value;
            $("#businesses-transferApplication-cboLevel").empty();
            $("#businesses-transferApplication-cboLevel").append(new Option("", ""));
            $("#businesses-transferApplication-cboMajor").empty();
            $("#businesses-transferApplication-cboMajor").append(new Option("", ""));
            febs.get(ctx + 'college/levelSelect?collegeId=' + collegeId, null, function (data) {
                let list = data.data;
                for (let i = 0; i < list.length; i++) {
                    let level = list[i];
                    $("#businesses-transferApplication-cboLevel").append(new Option(level.levelName, level.id));
                }
                //重新渲染下拉菜单
                form.render("select");
            });
        })

        //院校层次专业联动
        form.on('select(cboLevel)', function (data) {
            let collegeId = $("#businesses-transferApplication-cboCollege").val();
            let levelId = data.value;
            $("#businesses-transferApplication-cboMajor").empty();
            $("#businesses-transferApplication-cboMajor").append(new Option("", ""));
            febs.get(ctx + 'college/majorSelect?collegeId=' + collegeId + "&levelId=" + levelId, null, function (data) {
                let list = data.data;
                for (let i = 0; i < list.length; i++) {
                    let major = list[i];
                    $("#businesses-transferApplication-cboMajor").append(new Option(major.fullName, major.id));
                }
                //重新渲染下拉菜单
                form.render("select");
            });
        })
        //异动类型下拉菜单
        $.ajax({
            url: ctx + 'transferApplication/transferTypeList',
            success: function (res) {
                //console.log(res);
                if (res.code == 200) {
                    for (var i = 0; i < res.data.length; i++) {
                        $("#businesses-transferApplication-cboTransferType").append("<option value='" + res.data[i].id + "'>" + res.data[i].detail + "</option>");
                    }
                    form.render("select");
                }
            }
        });
        //构建用户树
        treeSelect.render({
            // 选择器
            elem: '#transferApplication-cboUser',
            // 数据
            data: ctx + 'transferApplication/userDeptTree',
            // 异步加载方式：get/post，默认get
            type: 'get',
            // 占位符
            placeholder: '请选择',
            // 是否开启搜索功能：true/false，默认false
            search: true,
            style: {
                folder: { // 父节点图标
                    enable: true // 是否开启：true/false
                },
                line: {
                    enable: true
                }
            },
            // 点击回调
            click: function (d) {
                //console.log(d.current.parent);
                $("#transferApplication-cboUser").val(d.current.id);
            },
            // 加载完成后的回调函数
            success: function (d) {
                console.log(d);
            }
        });
        initTable();
        table.on('sort(transferApplicationTable)', function (obj) {
            sortObject = obj;
            tableIns.reload({
                initSort: obj,
                where: $.extend(getQueryParams(), {
                    field: obj.field,
                    order: obj.type
                })
            });
        });
        $(".layui-input").keyup(
            function (e) {
                if (e.which === 13) {
                    $view.find('#businesses-transferApplication-query').click();
                }
            });
        form.on('submit(query-form-submit)', function (data) {
            console.info("查询");
            let params = $.extend(getQueryParams(), {field: sortObject.field, order: sortObject.type});
            //console.info(params);
            tableIns.reload({where: params, page: {curr: 1}});
            return false;
        });
        $reset.on('click', function () {
            $searchForm[0].reset();
            sortObject.type = 'null';
            tableIns.reload({where: getQueryParams(true), page: {curr: 1}, initSort: sortObject});
        });
        $export.on('click', function () {
            let params = $.extend(getQueryParams(), {field: sortObject.field, order: sortObject.type});
            params.pageSize = $view.find(".layui-laypage-limits option:selected").val();
            params.pageNum = $view.find(".layui-laypage-em").next().html();
            febs.download(ctx + 'transferApplication/excel', params, '异动申请信息表.xlsx');
        });
        table.on('tool(transferApplicationTable)', function (obj) {
            let data = obj.data,
                layEvent = obj.event;
            console.info(data);
            if (layEvent === 'edit') {
                console.info("异动申请审批");
                console.info(data);
                if (data.approvalStatus === '待审批') {
                    febs.modal.open('异动申请审批', 'transferApplication/update/' + data.id, {
                        area: $(window).width() <= 750 ? '90%' : '50%',
                        btnAlign: 'c',
                        btn: ['同意', '驳回', '取消'],
                        yes: function (index, layero) {
                            $('#febs-transferApplication-update').find('#agree').trigger('click');
                        },
                        btn2: function (index, layero) {
                            $('#febs-transferApplication-update').find('#reject').trigger('click');
                            return false;
                        },
                        btn3: function (index) {
                            layer.closeAll();
                        }
                    });
                } else {
                    febs.modal.open('异动申请详情', 'transferApplication/update/' + data.id, {
                        area: $(window).width() <= 750 ? '90%' : '50%',
                        btnAlign: 'c',
                        btn: ['关闭'],
                        yes: function (index) {
                            layer.closeAll();
                        }
                    });
                }

            }
        });

        function initTable() {
            tableIns = febs.table.init({
                elem: $view.find('table'),
                id: 'transferApplicationTable',
                url: ctx + 'transferApplication/list',
                cols: [[
                    {field: 'id', title: '编号', minWidth: 60},
                    {field: 'batchName', title: '批次', minWidth: 75},
                    {field: 'collegeSimpleName', title: '院校简称', minWidth: 90},
                    {field: 'levelName', title: '层次', width: 75},
                    {field: 'majorSimpleName', title: '专业简称', minWidth: 90},
                    {field: 'stuName', title: '姓名', width: 75},
                    {field: 'identity', title: '身份证号', minWidth: 180},
                    {field: 'tel', title: '手机号', minWidth: 120},
                    {field: 'transferTypeId', hide: true},
                    {field: 'transferType', title: '异动类型', minWidth: 110},
                    {field: 'approvalStatusId', hide: true},
                    {field: 'approvalStatus', title: '审批状态', minWidth: 110},
                    {field: 'applicationTime', hide: true},
                    {field: 'opinion', title: '意见', minWidth: 60},
                    {field: 'userName', title: '班主任', minWidth: 80},
                    {title: '操作', toolbar: '#transferApplication-option', minWidth: 70}
                ]]
            });
        }

        function getQueryParams(flag) {
            let params = $searchForm.serializeJson();
            return params;
        }
    })
</script>